import React, {useEffect, useState} from "react";
import {
    Table,
    Pagination,
    ConfigProvider,
} from "antd";
import zhCN from "antd/lib/locale/zh_CN";
import Service from "../../../service";
import "./xiaoshou.css";

export default function XiaoShou() {
    const columns = [
        {
            title: "订单",
            dataIndex: "order_no",
        },
        {
            title: "客户名称",
            dataIndex: "customer_name",
        },
        {
            title: "商品名称",
            dataIndex: "name_of_commodity",
        },
        {
            title: "商品图",
            dataIndex: "commodity_figure",
        },
        {
            title: "销售数量",
            dataIndex: "sales_amount",
        },
        {
            title: "折扣",
            dataIndex: "discount",
        },
        {
            title: "总金额",
            dataIndex: "allmoney",
        },
        {
            title: "备注",
            dataIndex: "note",
        },
        {
            title: "销售员",
            dataIndex: "salesman",
        }, {
            title: "销售时间",
            dataIndex: "entry_time",
        },
    ];

    const [data, setDate] = useState([])
    const [total, setTotal] = useState(0)
    const [currentPage, setCurrentPage] = useState(1);//当前页码
    const [pageSize, setPageSize] = useState(10);//每页展示条数

    //获取销售记录列表
    const getSalesRecord = (currentPage, pageSize) => {
        Service.writeOffService.getSalesRecord(currentPage, pageSize).then(data => {
            setTotal(data.count);
            setDate(data.data);
        }).catch(err => {
            console.log("销售记录请求出错啦！", err);
        })
    }
    const onChange = (page, size) => {
        setCurrentPage(page)
        setPageSize(size);
    }
    useEffect(() => {
        getSalesRecord(currentPage, pageSize);
    }, [currentPage, pageSize])
    return (
        <div>
            <Table columns={columns} dataSource={data} pagination={false}
                   rowKey={record => record.id}/>
            <ConfigProvider locale={zhCN}>
                <Pagination
                    className="GetPages"
                    total={total}
                    onChange={onChange}
                    defaultCurrent={currentPage}
                    showSizeChanger
                    showQuickJumper
                    showTotal={(total) => `总共 ${total} 页`}
                />
            </ConfigProvider>
        </div>
    );
}
